window.onload=function(){
    looktea=JSON.parse(localStorage.looktea)
    console.log(looktea);
    document.getElementById('teashowlei').innerHTML=`茶叶 > 全部 > ${looktea.lei} > ${looktea.name}`
    document.getElementById('teaname').innerHTML=`${looktea.name}`
    document.getElementById('teaprice').innerHTML=`￥${looktea.price}`
    document.getElementById('inpvalue').onchange=function(){
        if(this.value>=1){

        }else{
            alert('最少为1')
            this.value=1
        }
    }
}
function jian(){
    if(document.getElementById('inpvalue').value>1){
        document.getElementById('inpvalue').value--
    }else{
        alert('不能少于一个')
    }
}
function jia(){
    document.getElementById('inpvalue').value++
}
function addshopcar(){
    looktea=JSON.parse(localStorage.looktea)
    var shuliang= document.getElementById('inpvalue').value
    looktea.shuliang=shuliang
            let arr=[]
            let UserNewString=localStorage.ShopCar
            if(UserNewString==undefined || UserNewString==''||UserNewString==null||UserNewString=='[]'){
                let MaxID=1
                looktea.id=MaxID
                MaxID++
                localStorage.ShopCarMaxId=JSON.stringify(MaxID)
                arr.push(looktea)
                localStorage.ShopCar=JSON.stringify(arr)
            }else{
                var valueone=looktea.name
                let arrtwo=JSON.parse(localStorage.ShopCar)
                for (const iterator of arrtwo) {
                    if(iterator.name==valueone){
                        return alert('已存在购物车无需重复购买')
                    }
                }
                console.log(valueone);
                MaxID=JSON.parse(localStorage.ShopCarMaxId)
                looktea.id=MaxID
                MaxID++
                localStorage.ShopCarMaxId=JSON.stringify(MaxID)
                let arr=JSON.parse(localStorage.ShopCar)
                arr.push(looktea)
                localStorage.ShopCar=JSON.stringify(arr)
                alert('添加成功')
            }
}